package com.example.rabbitmq.demo1_modes.producer.mode03_sub;
import com.example.rabbitmq.enums.ExchangeEnum;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.nio.charset.StandardCharsets;
import java.util.Scanner;
/**
 * @Author songyahui
 * @Date 2023/7/7 22:44
 * @Description
 */

public class Produce {

    public static void buildMessage(Channel channel) throws Exception {
        //声明交换机
        channel.exchangeDeclare(ExchangeEnum.LOGS.name, BuiltinExchangeType.FANOUT);
        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()) {
            String message = scanner.next();
            //发送消息
            /*
             * 参数一: 交换机名称
             * 参数二: 交换机路由key值
             * 参数三: 额外参数
             * 参数四: 消息
             * */
            channel.basicPublish(ExchangeEnum.LOGS.name,"",null,message.getBytes(StandardCharsets.UTF_8));
        }

    }

}

